package com.github.gin.springboot.model;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by FSTMP on 2016/12/26.
 */
@Entity
@Table(name = "purchaseOrder")
@NamedEntityGraphs({
        @NamedEntityGraph(name = "graph.Order.items",
                attributeNodes = @NamedAttributeNode(value = "items", subgraph = "items"),
                subgraphs = @NamedSubgraph(name = "items", attributeNodes = @NamedAttributeNode("product")))
})
public class Order implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", updatable = false, nullable = false)
    private Long id = null;
    @Version
    @Column(name = "version")
    private int version = 0;

    @Column
    private String orderNumber;

    @OneToMany(mappedBy = "order")
    private Set<OrderItem> items = new HashSet<OrderItem>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public Set<OrderItem> getItems() {
        return items;
    }

    public void setItems(Set<OrderItem> items) {
        this.items = items;
    }
}
